package controller;

import com.alibaba.fastjson.JSONObject;
import entity.ForwordUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import service.ForwordUserService;

import javax.annotation.Resource;

/**
 * (ForwordUser)表控制层
 *
 * @author makejava
 * @since 2021-12-01 10:35:33
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/forwordUser")
public class ForwordUserController{
    /**
     * 服务对象
     */
    @Resource
    private ForwordUserService forwordUserService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ForwordUser selectOne(Integer id) {
        return this.forwordUserService.queryById(id);
    }

    /**
     * 用户登录校验接口
     * @param object
     * @return 查询结果,是否允许改用户登录
     * */
    @PostMapping("/login")
    @ResponseBody
    public JSONObject loginuser(@RequestBody JSONObject object){
        log.info("=============="+object.toString());
        JSONObject loginuser = forwordUserService.loginuser(object);
        return loginuser;
    }
    @PostMapping ("/gettest")
    @ResponseBody
    @CrossOrigin
    public void gettest(@RequestBody JSONObject object){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        WebAuthenticationDetails details = (WebAuthenticationDetails)authentication.getDetails();
        System.out.println(details);
    }
}